package com.pub.functions;

import java.math.BigDecimal;

/**
 * Created by IntelliJ IDEA.
 * @author zhuangzhonglong
 * @since 2008-9-11 15:13:03
 */
public class VarFuncs {

	public static boolean equals(Object v1, Object v2) {
		if(v1 == null && v2 == null) {
			return true;
		}
		if(v1 == null || v2 == null) {
			return false;
		}
		return v1.equals(v2);
	}

	public static Integer toInteger(Object value) {
		return toInteger(value, null);
	}

	public static Integer toInteger(Object value, Integer defaultValue) {
		if (value instanceof BigDecimal) {
			return toInteger((BigDecimal) value);
		}
		if(value instanceof Long) {
			return toInteger((Long) value);
		}
		if (value instanceof Double) {
			return toInteger((Double) value);
		}
		return defaultValue;
	}
	public static Integer toInteger(BigDecimal value) {
		if (value == null) return null;
		return value.intValue();
	}
	public static Integer toInteger(Long value) {
		if (value == null) return null;
		return value.intValue();
	}
	public static Integer toInteger(Double value) {
		if (value == null) return null;
		return value.intValue();
	}

	public static<T> T nvl(T value, T nullValue) {
		return value == null? nullValue: value;
	}
}
